<?php


namespace app\common\model;


class SysMessage extends BaseModel{

    public function getCreatedAtAttr($value){
        return date('Y-m-d',strtotime($value));
    }

    public function getContentAttr($value){
        return htmlspecialchars_decode($value);
    }

    public static function getList($categoryId,$userId){
        $list = self::where('category_id',$categoryId)->where(function($query) use($userId){
            if($userId){
                $query->where('to','0')->whereOr('to',$userId);
            }else{
                $query->where('to','0');
            }
        })->order('created_at','desc')
          ->order('weigh','desc')
          ->field('id,category_id,title,from,image,content,browse_num,created_at')
          ->select();
        return $list;
    }
}